const TOKEN_KEY = '__TOKEN';
const USER_INFO_KEY = '__USER_INFO';

export function getToken(): string | null {
  return localStorage.getItem(TOKEN_KEY);
}

export function setToken(token: string): void {
  localStorage.setItem(TOKEN_KEY, token);
}

export function clearStorage(): void {
  localStorage.clear();
}

export class UserInfo {
  email: string;

  constructor(email: string) {
    this.email = email;
  }
}

export function setUserInfo(userInfo: UserInfo): void {
  localStorage.setItem(USER_INFO_KEY, JSON.stringify(userInfo));
}

export function getUserInfo(): UserInfo | null {
  const userInfo = localStorage.getItem(USER_INFO_KEY);
  if (userInfo) {
    return JSON.parse(userInfo) as UserInfo;
  } else {
    return null;
  }
}
